<?php

namespace Lib;

require_once __DIR__ . '/../Config/constants.php';

class Autoload {

    private static $inst;
    public static function init() {
        if (! self::$inst)
            self::$inst = new self();
        
        return self::$inst;
    }

    public function __construct() {
        spl_autoload_register(__NAMESPACE__ . '\Autoload::lib');
        spl_autoload_register(__NAMESPACE__ . '\Autoload::app');
    }

    public static function lib($className) {
        $filename = DIR_ROOT . DS . str_replace("\\", DS, $className) . '.php';
        if (file_exists($filename)) {
            require_once $filename;
        }
    }

    public static function app($className) {
        $filename = DIR_APP . DS . str_replace("\\", DS, $className) . '.php';
        if (file_exists($filename)) {
            require_once $filename;
        }
    }
}